package awk.volitile;

/**
 * @ Author     ：haifeng.wang
 * @ Date       ：Created in 22:29 2018/7/28
 * @ Description：${description}
 * @ Modified By：
 * @ Version:     $version$
 */
public class TestVolitile {

    public static void main(String[] args) {
        final boolean flag = false;
        final ThreadDemo01 demo = new ThreadDemo01();
        new Thread(() -> {
            while (demo.isFlag()) {
                System.out.println("----------------------");
            }
        }).start();

        new Thread(() -> demo.setFlag(flag)).start();
    }

    static class ThreadDemo01 {

        private volatile boolean flag = true;

        public boolean isFlag() {
            return flag;
        }

        public void setFlag(boolean flag) {
            this.flag = flag;
        }
    }
}
